/*
The following codes replicate the results in Table 5
using different measures to proxy firm-level efficiency gap

*******************************************************
*Part I: 
* For Table 5
using welfare to gauge firm-level inefficiency gap
gap=VMPL-welfare.
*****************************************************

*/

*---------------------------------------------------------
*Part I: Results for alternative measures for labor cap 
*---------------------------------------------------------
cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear


* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)
gen share=perwage/perincome
*replace  lnabsG_gdp=ln(abs(VMPL-perwage)) if share<0.5
gen lnabsG_gdp=ln(absG_gdp)
replace  lnabsG_gdp=ln(abs(VMPL-perincome)+1) if share>0.5

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim


drop if VMPL<0



*5.1 column1 of Table 5
reg lnabsG_gdp  did,  cluster (ind4year)   

*5.2 column2:
reghdfe lnabsG_gdp  did Llnl, ///
absorb(t newid) cluster (ind4year)   

*5.3 column3 of Table 5
reghdfe lnabsG_gdp  did Llnl  Ltfp_op   Llnage  LlnkL LlnRD export_intensity Lfinance2, ///
absorb(t newid) cluster (ind4year)   


*5.4 column4 of Table 5
reghdfe lnabsG_gdp  did  Llnl Ltfp_op   Llnage  LlnkL LlnRD export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output   post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   

***********************************************************************





/*
* Part II:
 using industry-ownershiop-procince-year average wage level to
contruct firm-level ineffieincy gap: VMPL-average wage. 

*/
cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear


* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)
gen share=perwage/perincome
bysort ind4_adj QiuType province t: egen ave_perwage=mean(perwage)
*replace  lnabsG_gdp=ln(abs(VMPL-perwage)) if share<0.5
gen lnabsG_gdp=ln(absG_gdp)
replace  lnabsG_gdp=ln(abs(VMPL-ave_perwage))
*replace  lnabsG_gdp=ln(abs(VMPL-perwage))

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim


drop if VMPL<0








*5.5 column 5 of Table 5
reg lnabsG_gdp  did,  cluster (ind4year)   

*5.6 column 5 of Table 5
reghdfe lnabsG_gdp  did Llnl, ///
absorb(t newid) cluster (ind4year)   

*5.7 column 5 of Table 5
reghdfe lnabsG_gdp  did Llnl  Ltfp_op   Llnage  LlnkL LlnRD export_intensity Lfinance2, ///
absorb(t newid) cluster (ind4year)   




*5.8 column 5 of Table 5
reghdfe lnabsG_gdp  did Llnl  Ltfp_op   Llnage  LlnkL LlnRD export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output   post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   

